﻿using FastReport;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsApp1.Common;

namespace WinFormsApp1.Leo.ListWeeks03
{
    public partial class SalesSummarys : Form
    {
        public SalesSummarys()
        {
            InitializeComponent();
        }
        public string frx;
        private void SalesSummarys_Load(object sender, EventArgs e)
        {
            Report report = new Report();
            if (!string.IsNullOrWhiteSpace(frx))
                report.Load(frx);


            string url = URLCommon.Url2+@"/WeekListOne_Leo/GetSalesSummary";
            HttpClient client = new HttpClient();
            topone whitepork = new topone();
            var content = new StringContent(JsonSerializer.Serialize<topone>(whitepork));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var results = info["data"].Value<JArray>();
            //var results = info["data"].Value<JToken>();
            //var resultss = results["list"].Value<JArray>();

            //// 加载报表模板，这里假设模板文件是 "YourReportTemplate.frx"
            report.Load(@"../../../Reports\销售汇总\333.frx");

            DataSet ds = new DataSet();
            DataTable fr_dt = new DataTable();
            fr_dt.TableName = "baseInfos";
            fr_dt.Columns.Add("UPCDataName", typeof(String));//*****列名设置需要与标签模板一致*****
            fr_dt.Columns.Add("EmployeeName", typeof(String));
            fr_dt.Columns.Add("SalesTimes", typeof(String));
            fr_dt.Columns.Add("SalesNum", typeof(String));
            fr_dt.Columns.Add("SalesPeice", typeof(String));
            fr_dt.Columns.Add("ReturnNum", typeof(String));
            fr_dt.Columns.Add("ReturnPrice", typeof(String));


            for (int i = 0; i < results.Count; i++)
            {
                fr_dt.Rows.Add(results[i]["upcDataName"], results[i]["employeeName"], results[i]["salesTimes"], results[i]["salesNum"], results[i]["salesPeice"], results[i]["returnNum"], results[i]["returnPrice"]);

            }
            ds.Tables.Add(fr_dt);
            report.RegisterData(ds);//将数据传递至标签模板

            //report.Print();//打印标签
            designerControl1.Report = report;
            //restore the design layout. Without this code, the designer tool windows will be unavailable
            designerControl1.RefreshLayout();
        }

        public void FastProt()
        {

            Report report = new Report();

        }


        public class topone
        {




        };


        /// <summary>
        /// 销售汇总
        /// </summary>
        public class SalesSummaryRes
        {
            public int SalesSummaryId { get; set; }

            /// <summary>
            /// 商品代号
            /// </summary>
            public string UPCDataName { get; set; }

            /// <summary>
            /// 员工姓名
            /// </summary>
            public string EmployeeName { get; set; }

            /// <summary>
            /// 销售时间
            /// </summary>
            public DateTime SalesTimes { get; set; }

            /// <summary>
            /// 销售总数量
            /// </summary>
            public int SalesNum { get; set; }

            /// <summary>
            /// 销售总金额
            /// </summary>
            public int SalesPeice { get; set; }

            /// <summary>
            /// 退货数量
            /// </summary>
            public int ReturnNum { get; set; }

            /// <summary>
            /// 退货金额
            /// </summary>
            public int ReturnPrice { get; set; }
        }
    }
}
